package com.rock.securityresearch.common.equity.financereport

import cats.effect.{IO, Sync}
import com.rock.securityresearch.util.http.*
import org.typelevel.log4cats.Logger
import cats.syntax.functor.toFunctorOps
trait FinanceReports[F[_]] {
    def getFinanceReport(stockCode: String, reportType: FinanceReportType): F[FinanceReport]
}

object FinanceReports {
    def make[F[_] : Sync : Logger](): FinanceReports[F] = {
        new FinanceReports[F] {
            override def getFinanceReport(stockCode: String, reportType: FinanceReportType): F[FinanceReport] = {
                val url = s"http://quotes.money.163.com/service/${reportType.code}_$stockCode.html"
                Http[F].get(url).map { e =>
                    e.verifyOk
                    FinanceReport(reportType, FinanceReportCsvParser.parse(e.body, "GBK"))
                }
            }
        }
    }
}